#include "SockStream.h"
#include "SockConnector.h"

#include <time.h>
#include <signal.h>
#include <iostream>
#include <string.h>

int stop = 0;
void handle_signal (int sig)
{
    stop = 1;
}
int main ()
{
    signal (SIGINT, handle_signal);
    InetAddr remote_addr (8889, "127.0.0.1");
    SockStream peer;
    SockConnector connector;
    if (connector.connect (peer, remote_addr) != 0)
    {
	std::cout << "connect failed\n";
	return -1;
    }
    char buff[512] = {0};
#if 1
    while (stop == 0)
    {
	std::cin >> buff;
	peer.send (buff, strlen (buff));
	if (peer.recv (buff, 512) == 0)
	    break;
	std::cout << buff << std::endl;
    }
#else
    std::cin >> buff;
    peer.send (buff, strlen (buff));
    std::cout << "sleep 2 sec\n";
    sleep (2);
#endif
    peer.close ();
    return 0;
}
